#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
@Time        : 2021/11/11 14:31
@Author      : Albert Darren
@Contact     : 2563491540@qq.com
@File        : fastft.py
@Version     : Version 1.0.0
@Description : TODO
@Created By  : PyCharm
"""
from numpy import fft, abs, log1p
from skimage.io import imread
from DIP_experiment_5.util import contrast_show

PATH = "../experiment_fig/brain.tif"
font_path = "C:/Windows/Fonts/simhei.ttf"
im = imread(PATH)
# 傅里叶变换及对数增强
freq_im = fft.fft2(im)  # complex128
magnitude_spectra = abs(freq_im)  # float64
log_mag_im = log1p(magnitude_spectra)
# 幅度谱平移及对数增强
magnitude_spectra_shift = fft.fftshift(magnitude_spectra)
log_mag_shift_im = log1p(magnitude_spectra_shift)
# 幅度谱逆平移及对数增强
magnitude_spectra_ishift = fft.ifftshift(magnitude_spectra_shift)
log_mag_ishift_im = log1p(magnitude_spectra_ishift)
im_dict = {"幅度谱": magnitude_spectra, "log变换幅度谱": log_mag_im,
           "幅度谱平移变换": magnitude_spectra_shift, "log幅度谱平移变换": log_mag_shift_im,
           "幅度谱逆平移变换": magnitude_spectra_ishift, "log幅度谱逆平移变换": log_mag_ishift_im}
contrast_show(im_dict, (2, 3), wspace=0.3, font=font_path)
